package com.qian.apiserver.controller;

import com.qian.apiserver.model.*;
import com.qian.apiserver.service.*;
import com.qian.apiserver.tio.TioStartHandler;
import com.yaowk.api.common.PageReq;
import com.yaowk.api.common.PageResp;
import com.yaowk.api.system.model.Config;
import com.yaowk.api.system.service.IConfigService;
import com.yaowk.api.system.service.IMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/game/config")
@Api(tags = "游戏配置")
public class GameConfigController {
    @Autowired
    private IMenuService menuService;
    @Autowired
    private IOpenCardService openCardService;

    @Autowired
    private IConfigService configService;
    @Autowired
    private IRatioService ratioService;
    @Autowired
    private IWordService wordService;
    @Autowired
    private IConfig1Service config1Service;
    @Autowired
    private IProbabilityService probabilityService;
    @Autowired
    private TioStartHandler tioStartHandler;
    @GetMapping("/all")
    @ApiOperation("初始数据")
    public List<Config> findAll(){
        return configService.findAll();
    }
    @PostMapping("dataSave")
    @ApiOperation("修改数据")
    public void dataSave(Config config){
        configService.save(config);
    }
    @GetMapping("/ratio")
    @ApiOperation("牌型倍率")
    public List<Ratio> ratio(){
        return ratioService.findAll();
    }
    @PostMapping("/radioSave")
    @ApiOperation("修改倍率")
    public void save(Ratio ratio){
        ratioService.save(ratio);
    }
    @GetMapping("/probability")
    @ApiOperation("牌型概率")
    public List<Probability> probabilities(){
        return probabilityService.findAll();
    }
    @PostMapping("/probabilitySave")
    @ApiOperation("修改概率")
    public void probabilitySave(Probability probability) throws Exception {
//        tioStartHandler.send(probability.toString());
        probabilityService.save(probability);
    }
    @GetMapping("/rate")
    @ApiOperation("货币汇率")
    public List<Config1> allR(){
        return config1Service.findAll();
    }
    @PostMapping("rateSave")
    @ApiOperation("修改汇率")
    public void rateSave(Config1 config1){
        config1Service.save(config1);
    }

    @PostMapping("/save")
    @ApiOperation("开牌设置")
    public void save(OpenCard openCard){
        openCardService.save(openCard);
    }

    @GetMapping("/record")
    @ApiOperation("开牌历史记录")
    public PageResp<OpenCard> find(PageReq pageReq){
        pageReq.setPageSize(10);
        return openCardService.findAll(pageReq);
    }


}
